package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    Integer countByCategoryId(Long categoryId);

    /**
     * 根据 id 获取菜品信息
     *
     * @param id
     * @return dish
     */
    @Select("select * from dish where id = #{id}")
    Dish getDishById(Long id);

    List<Dish> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> list(Integer categoryId);

    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    // 设置useGeneratedKeys和keyProperty 返回自增的主键 id
    @Insert("insert into dish (name,category_id,price,image,description,status,create_time,update_time,create_user,update_user) values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Dish dish);
}
